package river_city_ransom.implementations;

import java.util.List;

import exceptions.ComposantError;
import river_city_ransom.services.Bloc;
import river_city_ransom.services.Dimensions;
import river_city_ransom.services.Objet;
import river_city_ransom.services.Position;
import river_city_ransom.services.Terrain;
import tools.Toolbox;


public class Terrain_I implements Terrain {
	private Dimensions dimensions;
	private List<Bloc> blocs;
	private List<Objet> objets;
	
	public Terrain_I(Dimensions d, List<Bloc> b, List<Objet> lo) {
		try {
			init(d, b, lo);
		}
		catch(Exception e) {
			System.err.println(e.getMessage());
		}
	}

	@Override
	public boolean equals(Object o){
		/*if(!(o instanceof Terrain)){
			return false;
		}

		if (Toolbox.equals(((Terrain)o).blocs(), blocs())){
			return false;
		}*/
		return true;
		
	}
	
	/** ________________________________________________________ CONSTRUCTORS */
	@Override
	public void init(Dimensions d, List<Bloc> b, List<Objet> lo) throws ComposantError {
		this.dimensions = d;
		this.blocs = b;
		this.objets = lo;
	}

	/** _________________________________________________________ OBSERVATORS */
	@Override
	public Dimensions dimensions() {
		return dimensions;
	}

	@Override
	public List<Bloc> blocs() {
		return blocs;
	}

	@Override
	public Bloc bloc(Position p) throws ComposantError {
		for(Bloc b : blocs()) {
			if(Toolbox.equals(b.position(), p)) {
				return b;
			}
		}
		return null;
	}

	@Override
	public List<Objet> objets() {
		return objets;
	}

	/** ___________________________________________________________ OPERATORS */
	@Override
	public void setBloc(Bloc bloc) throws ComposantError {
		blocs.add(bloc);
	}

	@Override
	public void delBloc(Bloc bloc) throws ComposantError {
		blocs.remove(bloc);
	}

	@Override
	public void addObjet(Objet o) throws ComposantError {
		objets.add(o);
	}

	@Override
	public void delObjet(Objet o) throws ComposantError {
		objets.remove(o);
	}
}
